package com.dulichdanang.location.location;

import lib.map.MyMedia;

import com.dulichdanang.R;
import com.dulichdanang.R.layout;
import com.dulichdanang.R.menu;

import android.os.Bundle;
import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.graphics.Color;
import android.util.Log;
import android.view.Menu;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabSpec;

public class LocationActivity extends TabActivity {

	TabHost tabHost;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_location);
	    tabHost = getTabHost();
	    Bundle re = this.getIntent().getExtras();
	    // Get from list location (search or watch format : id-locationName
		String[] temp = (re.getString("data")).split("-");
		String id = temp[0],name = temp[1];
		Location currentLo = new Location();
	    //Get loaction
	    currentLo = currentLo.getDetaill(temp[0]);
		//Tabhost for tab1
		TabSpec tab1Spec = tabHost.newTabSpec("Detail");
		tab1Spec.setIndicator("Detail",getResources().getDrawable(R.drawable.icon_tab_detail));
		Intent tab1Intent = new Intent(LocationActivity.this,LocationDetailActivity.class);
		// send itent formatt : id-name
		tab1Intent.putExtra("data",id+"-"+name);
		tab1Spec.setContent(tab1Intent);
		//Tabhost for tab2
		TabSpec tab2Spec = tabHost.newTabSpec("Images");
		tab2Spec.setIndicator("Images",getResources().getDrawable(R.drawable.icon_tab_image));
		Intent tab2Intent = new Intent(LocationActivity.this,LocationImageActivity.class);
		// send itent formatt : id-name-image
		tab2Intent.putExtra("data",id+"-"+name+currentLo.image);
		tab2Spec.setContent(tab2Intent);
		//Tabhost for tab1
		final TabSpec tab3Spec = tabHost.newTabSpec("Map");
		tab3Spec.setIndicator("Map",getResources().getDrawable(R.drawable.icon_tab_map));
		Intent tab3Intent = new Intent(LocationActivity.this,LocationMapActivity.class);
		// send itent formatt : id-name-ordinate
		tab2Intent.putExtra("data",id+"-"+name+currentLo.ordinate);
		tab3Spec.setContent(tab3Intent);
		tabHost.addTab(tab1Spec);
		tabHost.addTab(tab2Spec);
		tabHost.addTab(tab3Spec);
		 Location location = new Location();
	        location.id = 11;
	        location.keywork = "Cong vien 29/3,Da Nang";
	        location.name = "Công viên 29/3";
	        location.image = MyMedia.LoadImageFromWebOperations("http://images.travelpod.com/tw_slides/ta00/f2d/dfe/12986111629-tpfil02aw-10339.jpg", location.name);
//		//Set color for tab]
//		try {
//		tabHost.getTabWidget().getChildAt(0).setBackgroundColor(Color.parseColor("#7f9ced"));
//		for(int i=1;i<tabHost.getTabWidget().getChildCount();i++){
//    		tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#4c619e"));
//		}
//		}
//		catch(Exception ex){
//			Log.w("er", ex.toString());
//		}
		OnTabChangeListener tabChange = new OnTabChangeListener() {
			
			@Override
			public void onTabChanged(String tabId) {
//				// TODO Auto-generated method stub
//				Log.w("tab is chose : ", tabId);
//				int current=tabHost.getCurrentTab();
//				for(int i=0;i<tabHost.getTabWidget().getChildCount();i++){
//					System.out.println(i);
//					if(i==current){
//						Log.w("current",i+"");
//						tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#7f9ced"));
//					}else{
//						Log.w("not choose", i+"");
//						tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#4c619e"));
//					}
//		    		//Log.w("id",ts.getTag().toString()+tab3Spec.getTag().toString());
//		    		//setBackgroundColor(Color.parseColor("#4c619e"));
//				}
			}
		};
		tabHost.setOnTabChangedListener(tabChange);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_location, menu);
		return true;
	}
	private TabHost getMyTabHost(){
		return tabHost;
	}

}
